package service

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto/rpc"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func GetMember(c *gin.Context) {
	favorite, err := config.VideoRpcClient.GetMember(c, &__.GetMemberReq{})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "查询会员套餐失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "查询会员套餐成功", "data": gin.H{
		"list": favorite.List,
	}})
	return
}
func AliPayCallback(c *gin.Context) {
	log.Println("-------------------------------收到支付宝回调-------------------------")
	err := c.Request.ParseForm()
	if err != nil {
		return
	}
	form := c.Request.PostForm
	orderSn := form["out_trade_no"][0]
	tradeStatus := form["trade_status"][0]
	
	_, err = config.VideoRpcClient.AliPayCallback(c, &__.AliPayCallbackReq{
		OrderSn:     orderSn,
		TradeStatus: tradeStatus,
	})
	if err != nil {
		log.Println("更新失败")
		return
	}
	log.Println("支付成功,更新完成")
	log.Println("-------------------------------支付宝回调结束-------------------------")
	return
}
